#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;

int n, m;
struct Node {
  int x, y;
} a[N];
int pre[N];
int f[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i].x >> a[i].y;
  int ans = 1;
  deque<int> dq;
  int left = 1;
  int pos = 1;
  rep(i, 1, n) {
    while (pos < i) {
      while (dq.size() && a[dq.back()].x <= a[pos].x) dq.pop_back();
      dq.push_back(pos++);
    }
    while (dq.size() && a[dq.front()].x > a[i].y) {
      left = dq.front() + 1;
      dq.pop_front();
    }
    f[i] = i + 1 - left;
    ans = max(ans, f[i]);
  }
  cout << ans;
  return 0;
}